import { SFSchema, SFUISchemaItem } from "../interface";
import { BaseService } from "./base.service";

export class SFItemService<T = SFUISchemaItem> extends BaseService<T> {
  constructor(schema: SFSchema<T>, required: boolean) {
    super(schema, required);
  }

  getUI<R = SFUISchemaItem>(key?: keyof T, dft?: R) {
    const ui = (this._ui || {}) as T;
    if (!key) {
      return ui as unknown as R;
    }
    return (ui?.[key] || dft) as R;
  }

  setUI<K extends keyof T>(key: K, value: T[K]) {
    const ui = (this._ui || {}) as T;
    ui[key] = value;
  }
}
